package com.wave.redis.util;

import org.springframework.data.redis.core.RedisTemplate;

/**
 * @author 夕下风波
 * @date 2025-02-23 14:51
 * @description redis工具类
 */
public class RedisUtil {

    private final RedisTemplate<String, Object> redisTemplate;

    public RedisUtil(RedisTemplate<String, Object> redisTemplate) {
        this.redisTemplate = redisTemplate;
    }

    public void strSet(String prefix, String k, Object v) {
        redisTemplate.opsForValue().set(prefix + k, v);
    }

    public Object strGet(String prefix, String k) {
        return redisTemplate.opsForValue().get(prefix + k);
    }

    public <T> T strGet(String prefix, String key, Class<T> clazz) {
        Object value = redisTemplate.opsForValue().get(prefix + key);
        if (value == null) {
            return null;
        }
        return clazz.cast(value);
    }
}